package com.zsrt.java.day20161227.xww.demo4;
import java.util.Arrays;
/**
 * 一副牌五十四张牌
 * 三个人玩每人17张  3张底牌  
 * 
 * 思路：定义一个数组来装牌， 另外定义三个数组来装分发的牌，最后定义一个底牌；
 * 分发一张就要删除一张，当删除了17张后， 再循环相似的工作两次，删完剩下的三张牌就是底牌了。
 * @author zsrt
 *
 */
public class Puke {
	
	public static void test(){
		String[]pai={"黑桃A","黑桃2","黑桃3","黑桃4","黑桃5","黑桃6","黑桃7","黑桃8","黑桃9","黑桃10","黑桃J","黑桃Q","黑桃K","红桃A","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃K","梅花A","梅花2","梅花3","梅花4","梅花5","梅花6","梅花7","梅花8","梅花9","梅花10","梅花J","梅花Q","梅花K","红桃A","红桃2","红桃3","红桃4","红桃5","红桃6","红桃7","红桃8","红桃9","红桃10","红桃J","红桃Q","红桃K","方块A","方块2","方块3","方块4","方块5","方块6","方块7","方块8","方块9","方块10","方块J","方块Q","方块K","大王","小王"};
		String paizu1[]=new String[17];
		String paizu2[]=new String[17];
		String paizu3[]=new String[17];
		String dipai[]=new String[3];

		for(int i=0;i<17;i++){
				int ran = (int) (Math.random()*pai.length);
				//得到一张牌
				paizu1[i] = pai[ran];
				String[] newArray = new String[pai.length-1];
				
				//1：获取 被删除的数 的下标 index ==ran
				//2:以下标为基准 把 原来的数组oldArray 分为2部分  循环原来的数组
				//2.1 如果在index之前   原样复制到  新的数组中
				for(int j=0;j<ran;j++){
					String v = pai[j];
					newArray[j]=v;
				}
				//2.1 如果在index之后   把index-1 再复制
				for(int k=ran+1;k<pai.length;k++){
					String v = pai[k];
					newArray[k-1]=v;
				}
				pai = newArray;
		 }
		
		 for(int i=0;i<17;i++){
				int ran = (int) (Math.random()*pai.length);
				//得到一张牌
				paizu2[i] = pai[ran];
				String[] newArray = new String[pai.length-1];
				//1：获取 被删除的数 的下标 index ==ran
				//2:以下标为基准 把 原来的数组oldArray 分为2部分  循环原来的数组
				//2.1 如果在index之前   原样复制到  新的数组中
				for(int j=0;j<ran;j++){
					String v = pai[j];
					newArray[j]=v;
				}
				
				//2.1 如果在index之后   把index-1 再复制
				for(int k=ran+1;k<pai.length;k++){
					String v = pai[k];
					newArray[k-1]=v;
				}
				pai = newArray;
		 }
		 
		 for(int i=0;i<17;i++){
				int ran = (int) (Math.random()*pai.length);
				//得到一张牌
				paizu3[i] = pai[ran];
				
				String[] newArray = new String[pai.length-1];
				
				//1：获取 被删除的数 的下标 index ==ran
				//2:以下标为基准 把 原来的数组oldArray 分为2部分  循环原来的数组
				//2.1 如果在index之前   原样复制到  新的数组中
				for(int j=0;j<ran;j++){
					String v = pai[j];
					newArray[j]=v;
				}
				
				//2.1 如果在index之后   把index-1 再复制
				for(int k=ran+1;k<pai.length;k++){
					String v = pai[k];
					newArray[k-1]=v;
				}
				pai = newArray;
		 }
		 		for(int i=0;i<3;i++){
				int ran = (int) (Math.random()*pai.length);
				//得到一张牌
				dipai[i] = pai[ran];
				String[] newArray = new String[pai.length-1];
				//1：获取 被删除的数 的下标 index ==ran
				//2:以下标为基准 把 原来的数组oldArray 分为2部分  循环原来的数组
				//2.1 如果在index之前   原样复制到  新的数组中
				
				for(int j=0;j<ran;j++){
					String v = pai[j];
					newArray[j]=v;
				}
				
				//2.1 如果在index之后   把index-1 再复制
				for(int k=ran+1;k<pai.length;k++){
					String v = pai[k];
					newArray[k-1]=v;
				}
				pai = newArray;
		 }
		System.out.println("第一副牌："+Arrays.toString(paizu1));
		System.out.println("第二副牌：："+Arrays.toString(paizu2));
		System.out.println("第三副牌：："+Arrays.toString(paizu3));
		System.out.println("底牌："+Arrays.toString(dipai));
	}
	
	public static void main(String[] args) {
		test();
	}
}
